<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>

<html>
	<head>
		<title>工单核算管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			$("#table").datagrid({
				title:"工单核算管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/gd/listPageGDBase',
				rownumbers:true,
				singleSelect:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				    {title:'项目id',field:'xm_id',hidden:true},
				    {title:'客户id',field:'customer_id',hidden:true},
				    {title:'所属部门id',field:'dept_id',hidden:true}
				]],
				columns:[[
					{title:'工单编号',field:'gd_code',width:100,align:'center'},
					{title:'工单名称',field:'gd_name',width:200,align:'center'},
					{title:'工单状态',field:'gd_status',hidden:true},
					{title:'工单进度',field:'gd_status_desc',width:50,align:'center'},
				    {title:'项目编号',field:'xm_code',width:100,align:'center'},
				    {title:'项目名称',field:'xm_name',width:100,align:'center'},
				    {title:'所属部门',field:'dept_name',width:100,align:'center'},
				    {title:'客户',field:'customer',width:100,align:'center'},
					{title:'发起核算',field:'adjust_accounts',width:50,align:'center',formatter:function(value,rowData,rowIndex){
						if(rowData.gd_status >= <%=com.beaut.project.util.StaticData.WORKING%>){
		                    return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' title='核算明细' class='icon-transfer'  onclick=\"javascript:startAccounting('"+rowData.gd_status+"','"+rowData.id+"','"+rowData.gd_name+"','"+rowData.gd_code+"','"+rowData.xm_name+"','"+rowData.xm_code+"');\"/>";
						}
						return "";
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function balanceShenPi(gd_id,gd_name,gd_code,xm_name,xm_code){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认要成本核算？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/checkBalnace",
						data:"gd_id="+gd_id,
						success:function(rtJson){
							if(rtJson == '1'){
								$.ajax({
									type:'POST',
									url:"<%=contextPath %>/springMVC/gd/updateGDStatus",
									data:"gd_id="+gd_id+"&status=<%=com.beaut.project.util.StaticData.FREEZE%>",
									success:function(rtJson){
										if(rtJson.rtState == '0'){
											table_reload(rows.length);
											//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
										      var flowBusinessUrl="<%=contextPath %>/springViews/gd/gdAccounting.jsp?gd_id="+gd_id+"&gd_name="+gd_name+"&gd_code="+gd_code+"&xm_name="+xm_name+"&xm_code="+xm_code;
										      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_BALANCE_SHENPI%>")+"&businessId="+gd_id;
										      $.ajax({
															type:'POST',
															url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
															dataType:"JSON",
															data:param,
															success:function(rtJson){
																if (rtJson.rtState == '0'){
																	openDialogResize(rtJson.rtData.url,1000,800);
																}else{
																	warningInfo(rtJson.rtMsrg);
																}
																$(obj).show();
															}
												});
										}
										else{
											warningInfo(rtJson.rtMsrg);
										}
									}
								});
							}else{
								warningInfo("材料平衡或分包结算还有提交保存，请先保存！");
							}
						}
					});
				}
			});
	    } 
		
		
		//发起核算
		function startAccounting(status,gd_id,gd_name,gd_code,xm_name,xm_code){
			var rows=$('#table').datagrid('getSelections');
			if(status >= '<%=com.beaut.project.util.StaticData.ACCOUTING%>'){
				openDialogResize('<%=contextPath %>/springViews/gd/gdAccounting.jsp?status='+status+'&gd_id='+gd_id+'&gd_name='+gd_name+'&gd_code='+gd_code+'&xm_name='+xm_name+'&xm_code='+xm_code,2000, 1000);
				return;
			}
			$.messager.confirm('确认','您确认要发起核算？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/updateGDStatus",
						data:"gd_id="+gd_id+"&status=<%=com.beaut.project.util.StaticData.ACCOUTING%>",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
								openDialogResize('<%=contextPath %>/springViews/gd/gdAccounting.jsp?gd_id='+gd_id+'&gd_name='+gd_name+'&gd_code='+gd_code+'&xm_name='+xm_name+'&xm_code='+xm_code,2000, 1000);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		
		function doSearch()
		{
			var searchValue = $('#searchValue').val();
			var dept_id = $("#dept_id").combotree('getValue');
			$('#table').datagrid('load',{
				searchValue:searchValue,
				dept_id : dept_id
				});
		}
	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div align="right">
			          所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
				工单编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目名称或编码"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
